package com.lqs.sofp.service.impl;

import com.lqs.sofp.dao.UserInfoDao;
import com.lqs.sofp.dao.impl.UserInfoDaoImpl;
import com.lqs.sofp.entity.User;
import com.lqs.sofp.service.UserService;

public class UserServiceImpl implements UserService {
    @Override
    public User login(String username, String password) {
        //参数传递测试，有传到loginService层
        //System.out.println(username+"\t"+password+"参数成功传递到loginService层");

        UserInfoDao userinfo = new UserInfoDaoImpl();
        User user = userinfo.select(username);

        //参数回传测试，从数据库传回service层
//        if (user != null){
//            System.out.println(user.getUsername() + "\t" + user.getPassword() + "\t" + user.getPhone() + "\t" + user.getGender());
//        }else{
//            System.out.println("login---查无此人！");
//        }

        if (user != null) {
            if (user.getPassword().equals(password)) {
                return user;
            }
        }
        return null;
    }

    @Override
    public Boolean register(String username, String password, String phone, String gender) {
        User user = new User(username, password, phone, gender);

        UserInfoDao userInfo = new UserInfoDaoImpl();
        Boolean success = userInfo.update(user);

        return success;
    }
}
